package com.javaspeak.newfeaturesjava.projectcoin.diamondgenerics;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

/**
 * Since java 1.7 you can use empty diamond generics on the right hand side. 
 * The type is inferred from the left hand side:
 * <pre>
 * {@code
 * Map<String,String> map = new HashMap<>();
 * }
 * </pre>
 * 
 * @author John Dickerson
 */
public class DiamondGenericsApplication {

    public void runExample(){
        
        // Notice empty diamond after HashMap. Type is inferred from left 
        // hand side.
        Map<String,String> map = new HashMap<>();
        
        map.put( "Hello", "Ciao" );
        map.put( "World", "Mondo" );
        
        Set<Entry<String, String>> entrySet = map.entrySet();
        
        for ( Entry<String,String> entry : entrySet ){
            
            System.out.println( entry.getValue() );
        }
        
    }
    
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        
        DiamondGenericsApplication application = 
                new DiamondGenericsApplication();
        
        application.runExample();
    }

}
